from  marshmallow import fields

from extensions import marshmallow as ma


class PaginationParam(ma.Schema):
    current_page = fields.Int()
    page_size = fields.Int()


class PriceRangeSearch(ma.Schema):
    start = fields.Int()
    end = fields.Int()
    currency = fields.Str()


class ProductFilterParam(ma.Schema):
    pagination = fields.Nested(PaginationParam)
    keyword = fields.Str()
    price = fields.Nested(PriceRangeSearch)
    category_id = fields.Str()
    metadata = fields.Dict()
    brand_id = fields.Str()
    product_id = fields.Str()

    #
    # title = fields.Str()
    # average_price_max= fields.Float()
    # average_price_min = fields.Float()
    # start_publish_date = fields.DateTime()
    # end_publish_date = fields.DateTime()
    # type = fields.Str()

class ProductCreateParam(ma.Schema):
    id = fields.Str()
    tags = fields.Str()
    title = fields.Str(required=True)
    sub_title = fields.Str()
    cover_resource_id = fields.Str(required=True)
    category_id = fields.Str(required=True)
    metadata = fields.Dict(required=True)
    content = fields.Dict(required=True)
    # pagination = PaginationParam()
class MemberParam(ma.Schema):
    pass
class RegisterLocalParam(ma.Schema):
    login_name = fields.Str(required=True)
    password = fields.Str(required=True)
    member_info = fields.Nested(MemberParam)
    channel = fields.Str()

class LanguageCreateParam(ma.Schema):
    id = fields.Str(error_messages={'required': '不能为空'})
    screen_name = fields.Str(error_messages={'required': '不能为空'})
    type = fields.Str(error_messages={'required': '不能为空'})
    status = fields.Str(error_messages={'required': '不能为空'})
    logo = fields.Str(error_messages={'required': '不能为空'})

class MemberUpdateParam(ma.Schema):
    id = fields.Str()
    screen_name = fields.Str()
    first_name = fields.Str()
    last_name = fields.Str()
    grade = fields.Str()
    phone =  fields.Str()
    email = fields.Str()
    status = fields.Str()
    create_at= fields.Str()
    updatet_at = fields.Str()
    deal_count = fields.Str()
    level = fields.Str()
    secret_key = fields.Str()
    country = fields.Str()
    head_image_id = fields.Str()
    account_id = fields.Str()

class CreateShopCartParam(ma.Schema):
    member = fields.Str(error_messages={'required': '不能为空'})
    cart_items = fields.List(fields.Int)
    items_from = fields.Str()
    product_id = fields.Str()
    offer_id = fields.Str()
    additives = fields.List(fields.Str)

class CartItemAdditiveSchema(ma.Schema):
    # type = fields.Str(required=True, error_messages={'required': '不能为空'})
    # service_id = fields.Str(required=True, error_messages={'required': '不能为空'})
    # required = fields.Str()
    id  = fields.Str()

class ShopCartItemSchema(ma.Schema):
    #  product = fields.Str(required=True, error_messages=_default_error_messages)
    additives = fields.List(fields.Str)
    id = fields.Str()
    member = fields.Str()
    count = fields.Int(required=True, error_messages={'required': '不能为空'})
    offer = fields.Int(required=True, error_messages={'required': '不能为空'})
    source = fields.Str(required=True, error_messages={'required': '不能为空'})
    product_id = fields.Str()

class CurrencyParam(ma.Schema):
    id = fields.Str()
    screen_name = fields.Str()
    logo = fields.Str()
    # rate = fields.Str()
    # type = fields.Str()
    prefix = fields.Str()
    suffix = fields.Str()

class BrandParam(ma.Schema):
    id = fields.Str()
    brand_name = fields.Str(required=True,error_messages={'required':'不能为空'})
    describe = fields.Str()
    logo = fields.Str()

class TicketParam(ma.Schema):
    status = fields.Str()
    price = fields.Str()
    product_id = fields.Str()
    stock_info = fields.Dict(required=True)
    recommded = fields.Str(default=True)
    mask = fields.Str()


class CreatePaymentParam(ma.Schema):
    order_id = fields.List(fields.Str)
    channel = fields.Str()
    return_url = fields.Str()

class CheckoutParam(ma.Schema):
    currency = fields.Str(required=True)
    # fund_channel = fields.Str(required=True)
    cart_items = fields.List(fields.Int, required=True)
    notify_info = fields.Dict()

product_filter_param = ProductFilterParam()
product_create_param = ProductCreateParam()
language_create_param= LanguageCreateParam()
register_local_param = RegisterLocalParam()
member_update_param = MemberUpdateParam()
create_shop_cart_param = CreateShopCartParam()
shop_cart_item_param = ShopCartItemSchema()
currency_param = CurrencyParam()
brand_param = BrandParam()

ticket_param = TicketParam()
create_payment_param = CreatePaymentParam()
checkout_param = CheckoutParam(many=False)
